package com.yjy.xml.v2;

import com.alibaba.fastjson.JSON;
import com.yjy.xml.JaxbXmlUtil;

import javax.xml.bind.JAXBException;

public class MainTest {

    // 测试泛型类在第三级属性的场景【<ATSYH><TransReq><TransParam>业务参数部分</TransParam></TransReq></ATSYH>】
    public static void main(String[] args) throws JAXBException {
        String jsonStr = "{\"actArea\": \"actArea111\",\"actCur\": \"actCur111\",\"actNum\": \"actNum111\",\"isNonStandard\": \"isNonStandard123\"}";
        final ActBalQryReq_finGard actBalQryReq_finGard = JSON.parseObject(jsonStr, ActBalQryReq_finGard.class);
        System.out.println(JaxbXmlUtil.beanToXml(actBalQryReq_finGard));

        // bean转成xml
        FinGardTransaction finGardTransaction = new FinGardTransaction();
        finGardTransaction.setTransReq(new FinGardTransaction.TransReq<ActBalQryReq_finGard>() {{
            setTransParam(actBalQryReq_finGard);
        }});
        System.out.println(JSON.toJSONString(finGardTransaction));

        String xml = JaxbXmlUtil.beanToXml(finGardTransaction, ActBalQryReq_finGard.class);
        System.out.println(xml);

        // xml转成bean
        FinGardTransaction finGardTransaction1 = JaxbXmlUtil.xmlToBean(xml, FinGardTransaction.class, ActBalQryReq_finGard.class);
        System.out.println(JSON.toJSONString(finGardTransaction1));
    }
}
